//
//  PushMessageInfoViewController.m
//  BGM
//
//  Created by liuqin on 2018/12/3.
//  Copyright © 2018 com.alirtc.demo. All rights reserved.
//

#import "PushMessageInfoViewController.h"

#import "MessageHelpGroupViewController.h"
#import "MessagePayViewController.h"   //补发红包
#import "MessageHelpGroupViewController.h"
#import "ContactViewController.h"
#import "FriendViewController.h"


#import "CommonView.h"

#import "Common.h"
#import "MessageTopTableViewCell.h"
#import "MageRelationShipTableViewCell.h"
#import "MessageInfoTableViewCell.h"
#import "BGMHTTP.h"
#import "BGMUser.h"
#import "CommonViewController.h"
#import "BGMShareView.h"
#import "SVProgressHUD.h"
#import "BGMAcceptView.h"
#import "FriendViewController.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import "YBImageBrowser.h"
#import "BGMShareClass.h"
#import <NIMSDK/NIMSDK.h>


@interface PushMessageInfoViewController ()<UITableViewDelegate,UITableViewDataSource,BGMShareViewDelegate,MessageInfoTableViewCellDelegate,BGMAcceptViewDelegate,MageRelationShipTableViewCellDelegate>
@property (nonatomic, strong)UITableView *messageTable;
@property (nonatomic, strong)NSMutableDictionary *messageDic;

@property (nonatomic, strong)NSString *publishId;  //详情id
@property (nonatomic, strong)NSString *publishuserId;  //发布人id

@property (nonatomic, strong)BGMShareView *shareView;

@property (nonatomic, strong)NSMutableArray *groupArray;
@property (nonatomic, strong)NSArray *relationShipArray; //人脉关系

@property (nonatomic, assign)BOOL isShowAll;
@property (nonatomic, strong)BGMAcceptView *acceptView;
@property (nonatomic, assign)BOOL isMeAccept;


@end

@implementation PushMessageInfoViewController
- (void)changePulishType:(NSNotification *)noti{
    NSLog(@"%@",noti.object);
//          [[NSNotificationCenter defaultCenter]postNotificationName:@"PUSHLISHCOMPELE" object:@"publistcompele"];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navview.hidden = NO;
    self.titleBtn.hidden = NO;
    [self.titleBtn setTitle:@"详情" forState:UIControlStateNormal];
    self.isShowAll = NO;
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changePulishType:) name:@"PUSHLISHCOMPELE" object:nil];
    
    //转发好友成功
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fowardPusheMsgInfo:) name:@"fowardPusheMsgInfo" object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(shareAppSucess) name:@"shareAppSucess" object:nil];
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(thankGroupID:) name:@"ThankSGroup" object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addRedSuccess:) name:@"add_pay_money" object:nil];
    self.messageTable = [[UITableView alloc]initWithFrame:CGRectMake(0, self.navview.frame.size.height, SCREENW, SCREENH-self.navview.frame.size.height-80)];
    self.messageTable.delegate = self;
    self.messageTable.dataSource = self;
    self.messageTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.messageTable];
    [self getMessageInfo];
    
    
    UIApplication *app = [UIApplication sharedApplication];
    self.acceptView = [[BGMAcceptView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    self.acceptView.acceptDelegate = self;
    [app.keyWindow addSubview:self.acceptView];
    self.acceptView.hidden = YES;
    
    self.shareView = [[BGMShareView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, SCREENH)];
    self.shareView.shareDelegate = self;
    [app.keyWindow addSubview:self.shareView];
    self.shareView.hidden = YES;
    
}




#pragma mark ----UITABLEVIEWDELEGATE
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.isMe) {
        return 2;
    } 
    else{
        return 3;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==0) {
        return 70;
    }else if (indexPath.row ==1){
        return [self getRowHight];
    }else{
        if(self.isPublicMsg){
            return 160;

        }else{
            return 130;

        }
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==0) {
        static NSString *identfier = @"MessageTopTableViewCell";
        MessageTopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identfier];
        if (cell == nil) {
            cell = [[MessageTopTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identfier];
        }
        if(!self.isPublicMsg){
            [cell reloadTopView:self.messageDic userType:@"0"];  //好友发布详情
        }else{
            [cell reloadTopView:self.messageDic userType:@"1"];   //公益发布详情
        }
        return cell;
    }
    else if (indexPath.row==1){
        
        static NSString *identfier = @"MessageInfoTableViewCell";
        MessageInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identfier];
        if (cell == nil) {
            cell = [[MessageInfoTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identfier];
            cell.meseeageInfoDeleagte = self;
        }
        
        if (self.isShowAll) {
            
            if(self.isPublicMsg){
                
                NSArray *array = [self.messageDic objectForKey:@"pimages"];
                [cell sizeToFitMessageALL:self.messageDic isPhoto:array.count>0 ? 1 : 0 isMe:self.isMe isPublic:self.isPublicMsg];
                
            }else{
                
                  NSArray *array = [self.messageDic objectForKey:@"images"];
                  [cell sizeToFitMessageALL:self.messageDic isPhoto:array.count>0 ? 1 : 0 isMe:self.isMe isPublic:self.isPublicMsg];
            }
        }else{
            
            if(self.isPublicMsg){
                NSArray *array = [self.messageDic objectForKey:@"pimages"];
                [cell sizeToFitMessage:self.messageDic isPhoto:array.count>0 ? 1 : 0 isMe:self.isMe isPublic:self.isPublicMsg];
                
            }else{
                
                NSArray *array = [self.messageDic objectForKey:@"images"];
                [cell sizeToFitMessage:self.messageDic isPhoto:array.count>0 ? 1 : 0 isMe:self.isMe isPublic:self.isPublicMsg];
            }

        }
        return cell;
    }
    else{
        static NSString *identfier = @"MageRelationShipTableViewCell";
        MageRelationShipTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identfier];
        if (cell == nil) {
            cell = [[MageRelationShipTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identfier];
            cell.shipDelegate = self;
        }
       
        NSString *laber = @"";
        if(self.isPublicMsg){
            laber = [NSString stringWithFormat:@"【%@】",[self.messageDic objectForKey:@"laber"]];
        }
        [cell shipView:self.relationShipArray isPublicMsg:self.isPublicMsg form:laber];
            
       
        
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==0) {
        
        if(self.isPublicMsg){
            return;
        }
        
        NSString *logUerId = [BGMUser shareInstance].userId;
        NSString *fineid = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"userId"]];
        if ([logUerId isEqualToString:fineid]) {
            return;
        }
        
        FriendViewController *vc = [[FriendViewController alloc]init];
        vc.userId = logUerId;
        vc.userToken = [BGMUser shareInstance].userToken;
        vc.chUsersId = fineid;
        vc.ftype = UserFind;
        vc.otherImage = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"headImage"]];
        vc.otherName = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"userName"]];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}
- (CGFloat)getRowHight{
    NSArray *array;

    if (self.isPublicMsg) {
        array = [self.messageDic objectForKey:@"pimages"];
    }else{
        array = [self.messageDic objectForKey:@"images"];
    }
    
    if (self.isShowAll) {
        return [MessageInfoTableViewCell returnCellHightALL:self.messageDic isPhtot:array.count>0 ? 1 : 0 isMe:self.isMe isPublic:self.isPublicMsg];
    }else{
        return [MessageInfoTableViewCell returnCellHight:self.messageDic isPhtot:array.count>0 ? 1 : 0 isMe:self.isMe isPublic:self.isPublicMsg];
    }
}
// 查看全部
-(void)clickAll{
    
    self.isShowAll = !self.isShowAll;
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:1 inSection:0];
    [self.messageTable reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}




#pragma mark --跳转名信片页面
-(void)findFriendInfo:(int)i{
    if (i < self.relationShipArray.count-1) {
        NSDictionary *dic = [self.relationShipArray objectAtIndex:i];
        FriendViewController *vc = [[FriendViewController alloc]init];
        vc.userId = [BGMUser shareInstance].userId;
        vc.userToken = [BGMUser shareInstance].userToken;
        vc.chUsersId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"usersId"]];
        vc.otherImage = [NSString stringWithFormat:@"%@",[dic objectForKey:@"userHead"]];
        vc.otherName = [NSString stringWithFormat:@"%@",[dic objectForKey:@"userName"]];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

#pragma mark ------分享---
-(void)clickShare:(int)shareType{
    switch (shareType) {
        case 100:
        {//我的人脉
            
            NSString *loginUserid = [BGMUser shareInstance].userId;
            NSString *pushUserid = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"userId"]];
            
            if ([loginUserid isEqualToString:pushUserid]) {
                [SVProgressHUD showInfoWithStatus:@"自己不能转发自己的到人脉圈哦~"];

            }else{
                NSString *itisHelp = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"itisHelp"]];
                if ([itisHelp isEqualToString:@"YES"]) {
                    [SVProgressHUD showInfoWithStatus:@"已经帮朋友转发过啦~"];
                }else{
                    [SVProgressHUD show];
                    BGMShareClass *shareClass = [[BGMShareClass alloc]init];
                    [shareClass forwardPublishType:@"1" publishId:self.publishId pusblishUserId:self.publishuserId mobShareTitle:@""];
                }
            }
          
        }
            break;
        case 101:
        {
            [self forwardAppContact];  //跳入通讯录页面
        }
            break;
        case 102:
        {
            NSString *title;
            if (self.isPublicMsg) {
                title = [self.messageDic objectForKey:@"ptitle"];
            }else{
                title = [self.messageDic objectForKey:@"publishTitle"];
            }
            BGMShareClass *shareClass = [[BGMShareClass alloc]init];
            [shareClass sharetype:102 publishId:self.publishId pusblishUserId:self.publishuserId mobShareTitle:title];
        }
            break;
        case 103:
        {
            //微博
        }
            break;
            
        default:
            break;
    }
    self.shareView.hidden = YES;
}

//转发到好友聊天
- (void)fowardPusheMsgInfo:(NSNotification *)noti{
    BGMShareClass *shareClass = [[BGMShareClass alloc]init];
    [shareClass forwardPublishType:@"2" publishId:self.publishId pusblishUserId:self.publishuserId mobShareTitle:@""];
}
//转发到APP人脉圈成功
- (void)shareAppSucess{
     [self.messageDic setValue:@"YES" forKey:@"itisHelp"];
}
//跳转通讯录页面
- (void)forwardAppContact{
    
    ContactViewController *vc = [[ContactViewController alloc]init];
    vc.messageDic = self.messageDic;
    vc.isForward = YES;
    vc.messageId = self.publishId;
    if (self.helpUsersId.length==0||[self.helpUsersId isEqualToString:@"(null)"]) {
        self.helpUsersId = @"";
    }
    if (self.connectionUserId.length==0||[self.connectionUserId isEqualToString:@"(null)"]) {
        self.connectionUserId = @"";
    }
    vc.helpUsersId = self.helpUsersId.length>0 ? self.helpUsersId : @"";
    vc.connectionUserId = self.connectionUserId.length>0?self.connectionUserId:@"";
    UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:vc];
    [self.navigationController presentViewController:nc animated:YES completion:nil];
}
- (void)clickCancel{
    self.shareView.hidden = YES;
}


#pragma mark  ----------------------------
#pragma mark  ------------完成按扭----------
-(void)messagefinshed:(UIButton *)btn{
    if (btn.selected) {
        return;
    }
    [self judgeCompletePublish];
}
//判断帮忙完成
- (void)judgeCompletePublish{
    [SVProgressHUD show];
    NSDictionary *params = @{@"userToken":[BGMUser shareInstance].userToken,
                            @"userId":[BGMUser shareInstance].userId,
                            @"publishId":self.messageId};
    
    [BGMHTTP requestWithMethodName:@"publish/judgeCompletePublish" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
        dispatch_async(dispatch_get_main_queue(), ^{
            NSString *code = [NSString stringWithFormat:@"%@",[result objectForKey:@"code"]];
            if ([code isEqualToString:@"401"]) {
                [self addRedPay];
            }else{
                [self completePublish];
            }
        });
    }];
}
- (void)addRedPay{
   UIAlertController *alert = [CommonView getCommonAlert:@"" message:@"红包余额不足，请补发红包" ok:@"是" cancel:@"否" completed:^(NSInteger index) {
       if (index ==1) {
           MessagePayViewController *vc = [[MessagePayViewController alloc]init];
           vc.type = BGMAddRed;
           vc.publishId = self.messageId;
           [self presentViewController:vc animated:YES completion:nil];
       }else{
           [self completePublish];
       }
    }];
    [self presentViewController:alert animated:YES completion:nil];
}
// 补加红包成功
- (void)addRedSuccess:(NSNotification *)noti{
    [self completePublish];
}
//帮忙完成   判断是否有偿
- (void)completePublish{
   
    NSString *itisPaid = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"itisPaid"]];
    if ([itisPaid isEqualToString:@"1"]) {//调用群组接口
        [self gotoNextVC];
    }
       [self messageComplele:@""];  //无偿 直接完成
    
}
//答谢群组
- (void)gotoNextVC{
    [SVProgressHUD show];
    NSDictionary *params = @{@"publishId":[self.messageDic objectForKey:@"publishId"],@"userToken":[BGMUser shareInstance].userToken,@"usersId":[BGMUser shareInstance].userId};
    [BGMHTTP requestWithMethodName:@"publish/getGroupIid" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
        [SVProgressHUD dismiss];
        dispatch_async(dispatch_get_main_queue(), ^{
            NSArray *array = [result objectForKey:@"data"];
            if (array.count>0) {
                [self gotoMessageHelpGroupViewController:array];
            }else{
                [self messageComplele:@""];
            }
        });
    }];

}
- (void)gotoMessageHelpGroupViewController:(NSArray *)array{
   
    MessageHelpGroupViewController *vc = [[MessageHelpGroupViewController alloc]init];
    vc.pulishID = self.messageId;
    vc.userArray = array;
    UINavigationController *nc= [[UINavigationController alloc]initWithRootViewController:vc];
    [self presentViewController:nc animated:YES completion:nil];
    
}

- (void)thankGroupID:(NSNotification *)noti{
    id obj = noti.object;
    NSArray *array = obj;
    NSMutableString *str = [[NSMutableString alloc]init];
    for (int i = 0; i<array.count; i++) {
        NIMTeam *team = [array objectAtIndex:i];
        NSString *groupId = team.teamId;
        [str appendString:[NSString stringWithFormat:@"%@,",groupId]];
    }
    [self messageComplele:str];
}
- (void)messageComplele:(NSString *)groupStr{           //groupID
    NSDictionary *param = @{@"userToken":[BGMUser shareInstance].userToken,
                            @"userId":[BGMUser shareInstance].userId,
                            @"publishId":[self.messageDic objectForKey:@"publishId"],
                            @"groupId":groupStr
                            };
                       
        [BGMHTTP requestWithMethodName:@"publish/completePublish" parameters:param completion:^(BOOL success, NSError *error, NSDictionary *result) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *code = [NSString stringWithFormat:@"%@",[result objectForKey:@"code"]];
                if ([code isEqualToString:@"200"]) {
                    UIButton *btn = [self.view viewWithTag:1000];
                    btn.selected = YES;
                    btn.backgroundColor = bgmColor(244, 244, 244);;
//                    [SVProgressHUD showSuccessWithStatus:@"问题解决啦~"];
                }else{
                    [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"失败 code = %@,%@",code,[result objectForKey:@"desc"]]];
                }
            });
        }];
}
#pragma mark ----------------
#pragma mark --受理
-(void)clickAccept{
    self.acceptView.hidden = NO;
}
-(void)sendAccept:(NSString *)str{
  
    if (str.length == 0) {
        str = @"";
    }
    NSDictionary *params = @{@"userToken":[BGMUser shareInstance].userToken,
                             @"acceptanceId":[BGMUser shareInstance].userId,
                             @"publishId":self.publishId,
                             @"userId":self.publishuserId,
                             @"acceptanceMessage":str,
                             @"helpId":self.helpUsersId.length>0?self.helpUsersId:@""
                             };
    [BGMHTTP requestWithMethodName:@"index/publishAcceptance" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
        [SVProgressHUD showSuccessWithStatus:@"发送成功"];
        [self hiddenAcceptView];
        [[NSNotificationCenter defaultCenter]postNotificationName:@"HomeChangeInfo_info" object:@{@"acceptance":self.publishId}];
        __weak typeof(PushMessageInfoViewController *) weakSelf = self;
        dispatch_async(dispatch_get_main_queue(), ^{
            UIButton *btn = (UIButton *)[weakSelf.view viewWithTag:999];
            btn.selected = YES;
        });
    }];
    
}
- (void)hiddenAcceptView{
    self.acceptView.hidden = YES;
}
#pragma mark  -----------
#pragma mark 返回事件
- (void)clickBack{
    if(self.isPushRoot){
        [[NSNotificationCenter defaultCenter]postNotificationName:@"pushVCDismiss" object:nil];
    }else{
        [self.navigationController popViewControllerAnimated:YES];
    }
}
#pragma mark  -----------
#pragma mark 查看大图片
-(void)clickImage:(int)index{
    
    NSArray *imageArray ;
    if (self.isPublicMsg) {
        imageArray = [self.messageDic objectForKey:@"pimages"];
    }else{
        imageArray = [self.messageDic objectForKey:@"images"];
    }
    
    NSMutableArray *browserDataArr = [NSMutableArray array];
    [imageArray enumerateObjectsUsingBlock:^(NSString *_Nonnull urlStr, NSUInteger idx, BOOL * _Nonnull stop) {
        YBImageBrowseCellData *data = [YBImageBrowseCellData new];
        data.url = [NSURL URLWithString:urlStr];
        [browserDataArr addObject:data];
    }];
    
    YBImageBrowser *browser = [YBImageBrowser new];
    browser.dataSourceArray = browserDataArr;
    browser.currentIndex = index-100;
    [browser show];
    
}
#pragma mark  -----------
#pragma mark 底部按扭事件
- (void)clickBtn:(UIButton *)btn{
    int tag = (int)btn.tag;
    if (tag == 100) {  //评论
        CommonViewController *vc = [[CommonViewController alloc]init];
        vc.publishId = self.publishId;
        vc.publishHelpUserId = self.helpUsersId;
        vc.userId = self.publishuserId;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if( tag == 101){  //分享
        [self.shareView msgType:self.isPublicMsg];
        self.shareView.hidden = NO;
        
    }
    else if (tag == 999){// 受理  、、/////////////////
        if(btn.selected){
            [SVProgressHUD showInfoWithStatus:@"您已经受理啦！"];
        }else{
            [self clickAccept];
            
        }
 
    }
    else if(tag == 103){   //收藏
        btn.selected = !btn.selected;
        if(btn.selected){
            NSDictionary *params = @{@"userToken":[BGMUser shareInstance].userToken,@"userId":[BGMUser shareInstance].userId,@"publishId":self.publishId};
            [BGMHTTP requestWithMethodName:@"index/addFollow" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
                NSString *code = [NSString stringWithFormat:@"%@",[result objectForKey:@"code"]];
                if ([code isEqualToString:@"200"]) {
                    NSDictionary *dic = @{@"type":[NSString stringWithFormat:@"%d",self.isPublicMsg],@"pid":self.publishId,@"itisFollow":@"YES"};
                    [[NSNotificationCenter defaultCenter]postNotificationName:@"HomeChangeInfo_info" object:dic];
                }
            }];
        }else{
            NSDictionary *params = @{@"userToken":[BGMUser shareInstance].userToken,@"publishId":self.publishId,@"usersId":[BGMUser shareInstance].userId};
            
            [BGMHTTP requestWithMethodName:@"index/removeFollow" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
                NSString *code = [NSString stringWithFormat:@"%@",[result objectForKey:@"code"]];
                if ([code isEqualToString:@"200"]) {
                    NSDictionary *dic = @{@"type":[NSString stringWithFormat:@"%d",self.isPublicMsg],@"pid":self.publishId,@"itisFollow":@"NO"};
                    [[NSNotificationCenter defaultCenter]postNotificationName:@"HomeChangeInfo_info" object:dic];

                }
            }];
        }
    }
}
- (void)clickCommen{
    CommonViewController *vc = [[CommonViewController alloc]init];
    vc.publishId = self.publishId;
    vc.publishHelpUserId = self.helpUsersId;
    vc.userId = self.publishuserId;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 底部添加按扭
- (void)bottomAddButton{
    float w = 80;
    float spx = (SCREENW-w*4)/5;
    
    [self bottomCommonBtn:w];
    
    NSString *publishStatus;
    
    if(self.isPublicMsg){
        publishStatus = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"ptType"]];
    }else{
       publishStatus = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"publishType"]];
    }
    
    if ([publishStatus isEqualToString:@"2"]) {  //已经完成
        [self bottomFinshBtn:w status:publishStatus];
    }else{
        if ([[BGMUser shareInstance].userId isEqualToString:[NSString stringWithFormat:@"%@",self.publishuserId]]) {
            [self bottomForwardBtn:w spx:spx];
            [self bottomFinshBtn:w status:publishStatus];
        }else{
            [self bottomForwardBtn:w spx:spx];
            [self bottomAcceptBtn:w spx:spx];
            [self bottomLikeBtn:w spx:spx];
        }
    }
}
//评论按扭
- (void)bottomCommonBtn:(CGFloat )w{
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, SCREENH-w-(SCREENH>736?30:0), w, w)];
    [btn setImage:[UIImage imageNamed:@"pushMes_0"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"pushMes_0sele"] forState:UIControlStateSelected];
    [self.view addSubview:btn];
    btn.tag = 100;
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
}
//完成按扭
- (void)bottomFinshBtn:(CGFloat )w status:(NSString *)status{
    
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW-180, SCREENH-w+20, 170, 40)];
    [btn1 setTitle:@"帮忙完成" forState:UIControlStateNormal];
    [btn1 setTitle:@"已解决完成" forState:UIControlStateSelected];
    [btn1 setTitleColor:bgmmainColor forState:UIControlStateNormal];
    [btn1 setTitleColor:bgmmainColor forState:UIControlStateSelected];
    btn1.layer.masksToBounds = YES;
    btn1.layer.cornerRadius = 20;
    btn1.tag = 1000;
    btn1.showsTouchWhenHighlighted = NO;
    [self.view addSubview:btn1];
    [btn1 addTarget:self action:@selector(messagefinshed:) forControlEvents:UIControlEventTouchUpInside];
    if ([status isEqualToString:@"1"]) {
        btn1.selected = NO;
        btn1.backgroundColor = bgmyelloeColor;
    }else{
        btn1.selected = YES;
        btn1.backgroundColor = bgmColor(244, 244, 244);;
    }
}
//转发按扭
- (void)bottomForwardBtn:(CGFloat )w spx:(CGFloat)spx{
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(w+spx, SCREENH-w-(SCREENH>736?30:0), w, w)];
    [btn setImage:[UIImage imageNamed:@"pushMes_1"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"pushMes_1sele"] forState:UIControlStateSelected];
    [self.view addSubview:btn];
    btn.tag = 101;
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    //是否有帮红包
    NSString *helpResPackage = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"helpResPackage"]];
    
    if([helpResPackage floatValue]>0){
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(w-30, 5, 20, 25)];
        [imageV setImage:[UIImage imageNamed:@"push_red1"]];
        [btn addSubview:imageV];
    }
    //
    
    
}
//受理按扭
- (void)bottomAcceptBtn:(CGFloat )w spx:(CGFloat)spx{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(w*2+spx*2, SCREENH-w-(SCREENH>736?30:0), w, w)];
    [btn setImage:[UIImage imageNamed:@"pushMes_2"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"pushMes_2sele"] forState:UIControlStateSelected];
    [self.view addSubview:btn];
    btn.tag = 999;
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(w-30, 5, 20, 22)];
    [btn addSubview:image];
    image.tag = 0;
    //是否有偿
    NSString *itisPaid = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"itisPaid"]];
    
    if ([itisPaid isEqualToString:@"1"]) {
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(w-30, 5, 20, 25)];
        [imageV setImage:[UIImage imageNamed:@"push_red2"]];
        [btn addSubview:imageV];
    }
    
    NSString *itisAppent = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"itisAppent"]];
    if ([itisAppent isEqualToString:@"YES"]) {
        btn.selected = YES;
    }else{
        btn.selected = NO;
    }
    
}
//关注按扭
- (void)bottomLikeBtn:(CGFloat)w spx:(CGFloat)spx{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(w*3+spx*3, SCREENH-w-(SCREENH>736?30:0), w, w)];
    [btn setImage:[UIImage imageNamed:@"pushMes_3"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"pushMes_3sele"] forState:UIControlStateSelected];
    [self.view addSubview:btn];
    btn.tag = 103;
    [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    NSString *itisAppent = [NSString stringWithFormat:@"%@",[self.messageDic objectForKey:@"itisFollow"]];
    if ([itisAppent isEqualToString:@"YES"]) {
        btn.selected = YES;
    }else{
        btn.selected = NO;
    }
}
#pragma mark  -----------
#pragma mark 获取信息详情
- (void)getMessageInfo{
    if (self.isPublicMsg) {
        [self getPublicMsgInfo];
    }else{
        [self getUserPublishInfo];
    }
}

- (void)getUserPublishInfo{
    [SVProgressHUD show];
    NSDictionary *params = @{@"userToken":[BGMUser shareInstance].userToken,
                             @"userId":[BGMUser shareInstance].userId,
                             @"publishId":self.messageId,
                             @"connectionUserId":self.connectionUserId.length>0?self.connectionUserId:@"",
                             @"helpUsersId":self.helpUsersId.length>0?self.helpUsersId:@""
                             };
    [BGMHTTP requestWithMethodName:@"users/getUserPublishDetail" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
        NSString *code = [NSString stringWithFormat:@"%@",[result objectForKey:@"code"]];
        if([code isEqualToString:@"200"]){
            NSDictionary *dic = [result objectForKey:@"data"];
            [self reloadTableData:dic];
        }else{
            [SVProgressHUD showErrorWithStatus:@"请求详情失败"];
        }
        
    }];
}
- (void)reloadTableData:(NSDictionary *)dic{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.messageDic = [[NSMutableDictionary alloc]initWithDictionary:dic];
        self.publishId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"publishId"]];
        self.publishuserId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"userId"]];
        
        self.helpUsersId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"helpUsersId"]];
        self.relationShipArray = [dic objectForKey:@"usersHumanChain"];
        [self.messageTable reloadData];
        [self bottomAddButton];
    });
}
- (void)getPublicMsgInfo{
    [SVProgressHUD show];
    NSDictionary *params = @{@"userToken":[BGMUser shareInstance].userToken,
                             @"userId":[BGMUser shareInstance].userId,
                             @"publishId":self.messageId
                             };
    [BGMHTTP requestWithMethodName:@"users/getUserPublishDetailG" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
        NSString *code = [NSString stringWithFormat:@"%@",[result objectForKey:@"code"]];
        if([code isEqualToString:@"200"]){
            NSDictionary *dic = [result objectForKey:@"data"];
            [self messageWithPublic:dic];
        }else{
            [SVProgressHUD showErrorWithStatus:@"请求详情失败"];
        }
        
    }];
}
- (void)messageWithPublic:(NSDictionary *)dic{
    dispatch_async(dispatch_get_main_queue(), ^{
        self.messageDic = [[NSMutableDictionary alloc]initWithDictionary:dic];
        self.publishId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"pid"]];
        self.publishuserId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"uid"]];//
        
//        self.helpUsersId = [NSString stringWithFormat:@"%@",[dic objectForKey:@"helpUsersId"]];
        self.relationShipArray = [dic objectForKey:@"list"];
        
        [self.messageTable reloadData];
        [self bottomAddButton];
    });
}


@end
